# -*- encoding: utf-8 -*-
##############################################################################
#
##############################################################################

from odoo import api, fields, models, _
from odoo.addons import decimal_precision as dp
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_round


class MrpProduction(models.Model):
    """ Manufacturing Orders """
    _inherit = 'mrp.production'

    mo_done_date = fields.Datetime(u'完工时间')

    product_description = fields.Html(related='product_id.product_tmpl_id.product_description', string=u"产品说明")
    product_attention = fields.Html(string=u"注意事项")
    product_production_attribute_ids = fields.One2many("product.production.attribute.line", "production_id",
                                                       string=u"加工需求")

    @api.model
    def create(self, values):
        if values.get('product_id'):
            product = self.env['product.product'].browse(values.get('product_id'))
            if product.product_production_attribute_ids:
                values['product_production_attribute_ids'] = [(0, 0, {
                    "attribute_id": att_line.attribute_id.id,
                    "value_ids": [(6, 0, att_line.value_ids.ids)],
                }) for att_line in product.product_production_attribute_ids]
        production = super(MrpProduction, self).create(values)
        return production
